#include <iostream>
#include <algorithm>


using namespace std;
const int N = 1e4 + 10, M = 2e4 + 10;
int fa[N];
int n, m, s, t;
struct node
{
	int u, v, w;
}a[M];
bool cmp(node& x, node& y)
{
	return x.w < y.w;
}
int find(int x)
{
	return fa[x] == x ? x : find(fa[x]);
}
void uni(int x, int y)
{
	int fx = find(x), fy = find(y);
	fa[fx] = fy;
}
int main()
{
	cin >> n >> m >> s >> t;
	for (int i = 1; i <= m; i++) cin >> a[i].u >> a[i].v >> a[i].w;
	for (int i = 1; i <= n; i++) fa[i] = i;
	sort(a + 1, a + 1 + m, cmp);

	for (int i = 1; i <= m; i++)
	{
		uni(a[i].u, a[i].v);
		if (find(s) == find(t))
		{
			cout << a[i].w << endl;
			break;
		}
	}
	return 0;
}